package jwdt.xadmin.custom.service.impl;

import java.util.List;

import jwdt.common.dao.BaseDao;
import jwdt.xadmin.custom.bean.TCar;
import jwdt.xadmin.custom.bean.TCarsq;
import jwdt.xadmin.custom.bean.TCarwh;
import jwdt.xadmin.custom.service.CarManageService;
import jwdt.xadmin.system.bean.TSystem;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.util.StringUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;

public class CarManageServiceImpl implements CarManageService {

	private BaseDao<TCar> baseDao;
	
	public void setBaseDao(BaseDao<TCar> baseDao) {
		this.baseDao = baseDao;
	}

	@Override
	public PageUtil doList(PageUtil pu,TCarwh tc) throws Exception{
		String where = "";
		String cph = tc.getCph();
		if(!StringUtil.nullOrBlank(cph)) {
			where += " cph like '%" + cph + "%'";
			
		}
		String sql = " order by id desc";
		pu.doList(TCarwh.class,where+sql);
		//创造json数据对象
		return pu;
	}

	@Override
	public PageUtil doList(PageUtil pu,TCarsq tc,String status) throws Exception{
		String where ="";
		String cph = tc.getCph();
		if(!StringUtil.nullOrBlank(cph)) {
			where += " cph like '%" + cph + "%'";
			
		}
		if(!StringUtil.nullOrBlank(status)) {
			if(!StringUtil.nullOrBlank(cph)) {
				where += " and";
				
			}
			where += " status='"+status+"'";
		}
		String sql = " order by status asc";
		pu.doList(TCarsq.class,where+sql);
		//创造json数据对象
		return pu;
	}

	@Override
	public PageUtil doList(PageUtil pu,TCar tc,String status) throws Exception{
		String where = "";
		String cph = tc.getCph();
		if(!StringUtil.nullOrBlank(cph)) {
			where += " cph like '%" + cph + "%' and";
			
		}
		if(!StringUtil.nullOrBlank(status)) {
			where += " status='"+status+"'";
		}
		String sql = " order by id desc";
		pu.doList(TCar.class,where+sql);
		//创造json数据对象
		return pu;
	}

	@Override
	public String carAddact(TCar obj) throws Exception{
		return baseDao.doAddObj(obj);
		
	}

	@Override
	public TCar carEdit(int id) throws Exception{
		return baseDao.doLoadObj(TCar.class,id);
		
	}

	@Override
	public String carEditact(TCar obj,int id) throws Exception{
			String ret = baseDao.doUpdateObj(TCar.class, id, obj);
			return ret;
	}

	@Override
	public String carDel(int id) throws Exception {
		return baseDao.doDelObj(TCar.class,id);
	}

	@Override
	public PageUtil pagecar(Form f, Module m) throws Exception{
		TSystem Tsystem=(TSystem) Jdb.get().get(TSystem.class, 1);
		int page = f.getInt("page", 1);
		int pageSize = f.getInt("pageSize", Tsystem.getAdminnum());
		
		String sql = " order by id desc";

		PageUtil pu = new PageUtil(TCarwh.class, sql, page, pageSize);
		return pu.setUrl(m.getFullPath() + ".do");
	}
	
	
	@Override
	public List getFlmx(int flid) {
		return Jdb.get().query("SELECT MXMC, MXDM FROM jwdt_zd_flmx where FLID=?", new Object[]{flid});
	}
	
	@Override
	public List rsxx() throws Exception{
		return Jdb.get().query("select * from t_rsxx");
		
	}
	@Override
	public List carXxcx(String status) throws Exception{
        return Jdb.get().query("SELECT * FROM(SELECT * FROM t_car a LEFT JOIN (SELECT MXMC, MXDM FROM jwdt_zd_flmx WHERE FLID='15') b ON a.cllx=b.MXDM) a LEFT JOIN (SELECT id as rsxx_id, fullname FROM t_rsxx) b ON a.jsy=b.rsxx_id where status='" + status + "'");
		
	}
	
}
